package com.feng.exma.controller;

import com.feng.common.dto.PageDto;
import com.feng.common.vo.ApiRest;
import com.feng.common.vo.PageResult;
import com.feng.exma.dto.ExamSaveDto;
import com.feng.exma.entity.Exam;
import com.feng.exma.service.ExamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author feng
 * @since 2023-03-22 17:35:29
 */
@RestController
@RequestMapping("exam")
@Api(tags = "考试模块")
@CrossOrigin
public class ExamController {


    @Autowired
    private ExamService examService;


    @PostMapping("/save")
    @ApiOperation("添加考试")
    public ApiRest save(@RequestBody ExamSaveDto examSaveDto){
        return examService.create(examSaveDto);
    }

    @PreAuthorize("hasAnyRole('ROLE_')")
    @PostMapping("find")
    @ApiOperation("条件分页查询考试")
    public PageResult<Exam> pagingExam(@RequestBody PageDto<Exam> pageDto) {
        return examService.pagingExam(pageDto);
    }

    @DeleteMapping("{examId}")
    @ApiOperation("逻辑删除")
    @Transactional
    public ApiRest deleteExam(@PathVariable String examId) {
        return examService.removeById(examId, true) ?
                ApiRest.success() : ApiRest.failure();
    }

    @GetMapping("{id}")
    @ApiOperation("查询单个考试信息")
    public ApiRest selectOne(@PathVariable String id) {
        return null;
    }
}
